<?php
/**
 * 首页管理
 * author:ty
 * date:2018-2-1
*/
namespace App\Http\Controllers;

use App\Http\Models\COMMON;
use App\Http\Models\Fitment;
use App\Http\Models\Index;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

class IndexController extends Controller
{
    /**
     * @per_page 必填参数 展示数量 *
     * @fitments_type 家具类型【1家用/2办公/3商用/14热门家具】
     * @rent_type 租赁方式【1随租随还，2租满即送】
     * @fitments_subcate_id 家具子分类id【桌子椅子凳子】
     * 【1=>[7=>办公桌，8=>办公椅，9=>文件柜，10=>配件]，2=>[31=>办公桌,32=>办公椅],3=>[33=>办公椅子,34=>办公桌]，14=>[35=>实木办公桌,36=>简约拼接桌,37=>职员办公椅]】
    */
    public function index()
    {
        $input_data = Input::all();
        //轮播图
        $carsouel_limit=Input::get('bangongzhuo_number','');
        $carousel = Index::carsouel($carsouel_limit);
        //热门家具
        $hotfitment = COMMON::hotfitment();

        //办公家用通用查询参数
        $request = array(
            'per_page'=>Input::get('per_page',3),
            'fitments_type'=>Input::get('fitments_type',1),
            'rent_type'=>Input::get('rent_type',2),
        );

        //办公桌
        if(isset($input_data['bangongzhuo_number']) && $input_data['bangongzhuo_number']!=''){
            $request['per_page']=$input_data['bangongzhuo_number'];
        }
        $result['fitments_subcate_id']=7;
        $bangongzhuo = Fitment::fitment_classify($request);

        //办公椅
        if(isset($input_data['bangongyi_number']) && $input_data['bangongyi_number']!=''){
            $request['per_page']=$input_data['bangongyi_number'];
        }
        $result['fitments_subcate_id']=8;
        $bangongyi = Fitment::fitment_classify($request);

        //办公柜
        if(isset($input_data['bangonggui_number']) && $input_data['bangonggui_number']!=''){
            $request['per_page']=$input_data['bangonggui_number'];
        }
        $result['fitments_subcate_id']=9;
        $bangonggui = Fitment::fitment_classify($request);
        $data=array(
            'carsouel' => $carousel,
            'hotfitment' => $hotfitment,
            'bangongzhuo' => $bangongzhuo,
            'bangongyi' => $bangongyi,
            'bangonggui' => $bangonggui
        );
        $result = ['code'=>200,'messages'=>'首页数据','result'=>$data];
        return response()->json($result);
    }

}
